import { getOptionProps, getAttrs, getListeners } from 'ant-design-vue/es/_util/props-util'
import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props'
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties'
import _defineProperty from 'babel-runtime/helpers/defineProperty'
import classNames from 'classnames'
import ZCheckbox from './ZCheckbox'
const ACheckbox = require('ant-design-vue/es/checkbox/Checkbox')
function noop () { }

const Checkbox = {}
Object.assign(Checkbox, ACheckbox.default)

Object.assign(Checkbox, {
  name: 'ZCheckbox',
  render () {
    const _this2 = this,
      h = arguments[0],
      _classNames = {},
      checkboxGroup = this.checkboxGroupContext,
      $slots = this.$slots

    const props = getOptionProps(this)
    const children = $slots.default

    const _getListeners = getListeners(this),
      _getListeners$mouseen = _getListeners.mouseenter,
      mouseenter = _getListeners$mouseen === undefined ? noop : _getListeners$mouseen,
      _getListeners$mousele = _getListeners.mouseleave,
      mouseleave = _getListeners$mousele === undefined ? noop : _getListeners$mousele,
      restListeners = _objectWithoutProperties(_getListeners, ['mouseenter', 'mouseleave', 'input'])

    const customizePrefixCls = props.prefixCls,
      indeterminate = props.indeterminate,
      restProps = _objectWithoutProperties(props, ['prefixCls', 'indeterminate'])

    const getPrefixCls = this.configProvider.getPrefixCls
    const prefixCls = getPrefixCls('checkbox', customizePrefixCls)

    const checkboxProps = {
      props: Object.assign({}, restProps, { prefixCls: prefixCls }),
      on: restListeners,
      attrs: getAttrs(this)
    }
    if (checkboxGroup) {
      checkboxProps.on.change = function () {
        const _len = arguments.length, args = Array(_len)
        for (let _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key]
        }

        _this2.$emit.apply(_this2, ['change'].concat(args))
        checkboxGroup.toggleOption({ label: children, value: props.value })
      }
      checkboxProps.props.name = checkboxGroup.name
      checkboxProps.props.checked = checkboxGroup.sValue.indexOf(props.value) !== -1
      checkboxProps.props.disabled = props.disabled || checkboxGroup.disabled
      checkboxProps.props.indeterminate = indeterminate
    } else {
      checkboxProps.on.change = this.handleChange
    }
    const classString = classNames((_classNames, _defineProperty(_classNames, prefixCls + '-wrapper', true), _defineProperty(_classNames, prefixCls + '-wrapper-checked', checkboxProps.props.checked), _defineProperty(_classNames, prefixCls + '-wrapper-disabled', checkboxProps.props.disabled), _classNames))
    const checkboxClass = classNames(_defineProperty({}, prefixCls + '-indeterminate', indeterminate))
    return h(
      'label',
      {
        class: classString,
        on: {
          mouseenter: mouseenter,
          mouseleave: mouseleave
        }
      },
      [h(ZCheckbox, _mergeJSXProps([checkboxProps, { class: checkboxClass, ref: 'zCheckbox' }])), children !== undefined && h('span', [children])]
    )
  }
})

Object.assign(Checkbox.props, {
  defaultChecked: {
    type: String,
    default: '0'
  },
  checked: {
    type: String
  }
})

export default Checkbox
